package com.oliet.common.vo.permission;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.oliet.entity.Permissions;
import lombok.Data;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jiaZhenpeng
 * @Title: PermissionVO
 * @Package com.oliet.common.vo.permission
 * @Description: 权限显示数据
 * @date 2023-12-03 19:38
 */
@Data
public class PermissionVO {

    /**
     * 权限ID
     */
    private Long id;

    /**
     * 权限编码
     */
    private String code;

    /**
     * 权限名称
     */
    private String permissionName;

    /**
     * 权限类型
     */
    private String permissionType;

    /**
     * 描述
     */
    private String description;

    /**
     * 父权限ID
     */
    private Long parentId;

    /**
     * 菜单地址
     */
    private String resourceAddress;

    /**
     * 权限层级
     */
    private Integer level;

    /**
     * 显示位置
     */
    private String displayPosition;

    public static List<PermissionVO> poListConverVoList(List<Permissions> poList) {
        List<PermissionVO> result = Lists.newArrayList();
        if (CollectionUtil.isEmpty(poList)){
            return result;
        }
        result = poList.stream().map(po->{
            PermissionVO vo = new PermissionVO();
            BeanUtil.copyProperties(po, vo);
            return vo;
        }).collect(Collectors.toList());
        return result;
    }

    public static PermissionVO poConverVo(Permissions po) {
        PermissionVO vo = new PermissionVO();
        if (ObjectUtil.isEmpty(po)){
            return vo;
        }
        BeanUtil.copyProperties(po, vo);
        return vo;
    }


}
